#!/usr/bin/python
#***************************************************************************
# Copyright notice for this file:
#  Copyright (C) 2012 TheAxeMan
#  _______ _                               _    _
# |__   __| |     ___     /\          ___ | \  / |
#    | |  | |__  / _ \   /  \  __  _ / _ \|  \/  | __ _ _ __
#    | |  | '_ \|  __/  / /\ \ \ \/ |  __/| .  . |/ _` | '_ \
#    | |  | | | | (__/\/ ____ \ )  (| (__/| |\/| | (_| | | | |
#    |_|  |_| |_|\____/_/    \_._/\_.\____|_|  |_|\__,_|_| |_|
#
# Final Fantasy TAS scripts by TheAxeMan
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#***************************************************************************


from battlePlannerLib        import Combatant, BattleRandGenerator, CharType
from battlePlannerBattle     import Battle


class Garland(Combatant):
  damage = 15
  defense = 10
  num_hits = 1
  crit_threshold = 0
  hit_threshold = 142
  type = CharType.garland
  
class Lvl1Fighter(Combatant):
  damage = 10
  defense = 0
  num_hits = 1
  crit_threshold = 0
  hit_threshold = 166
  type = CharType.level1fighter

class GarlandBattle(Battle):
  partyFightCost = 160
  dust_seeds = 135
  startingHeroHp = 35
  
  def __init__(self):
    '''Override to add the right combatants'''
    self.rand_engine = BattleRandGenerator()
    self.rand_engine.seed = 51
    
    self.enemy_list = [Combatant(0) for i in xrange(9)]
    self.enemy_list[2] = Garland(106)
    self.party_list = [Lvl1Fighter(35) for i in xrange(4)]


def garland_demo():
  """Demonstrate battle flow for garland fight"""
  BattleRandGenerator.populateBattleOrderLookupTable()
  BattleRandGenerator.populateTargetLookupTable()
  
  garland = Garland(106)
  fighter = Lvl1Fighter(35)
  
  Lvl1Fighter.populateDamageLookupTable(garland)
  Garland.populateDamageLookupTable(fighter)
  
  garland_fight = GarlandBattle()

  order_list = []
  if 1:
    order_list.append([-1,2,-1,2])
    order_list.append([-1,-1,-1,2])
    order_list.append([2,2,2,-1])
    order_list.append([2,-1,2,2])
    wait_list = [1, 45, 66, 31]
  else:
    order_list.append([-1,2,-1,2])
    order_list.append([2,2,-1,2])
    order_list.append([-1,2,2,2])
    wait_list = [1, 27, 43]

  for i in xrange(len(wait_list)):
    garland_fight.rand_engine.useUpRands(2*garland_fight.partyMembersLiving())
    garland_fight.rand_engine.useUpRands(wait_list[i])

    #r = garland_fight.rand_engine.copy()
    #print r.getBattleOrder()
    #r = garland_fight.rand_engine.copy()
    #for j in xrange(34):
    #  print r.getRandInRange(0, 12),
    #print ""

    garland_fight.simulateRound(order_list[i], print_attack=True)
    print "seed is",garland_fight.rand_engine.seed
    print ""
    
    
if __name__ == "__main__":
  garland_demo()  
  